package com.group.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

public class CommonUtil {

	/**
	 * 获取一个map，通常用于controller层的json返回
	 */
	public static Map<String, String> getReturnMap(String key, String value) {
		Map<String, String> map = new HashMap<String, String>();
		map.put(key, value);
		return map;
	}
	
	/**
	 * 得到当前天数的date
	 */
	public static String getCurrentDate(String format) {
		String date = new SimpleDateFormat(format).format(new Date());
		return date;
	}
	
	/**
	 * 得到保存图片的地址
	 */
	public static String getUploadImgUrl(String projectName, MultipartFile file) {
		String ext = FilenameUtils.getExtension(file.getOriginalFilename());
		String uploadTime = new SimpleDateFormat("yyyy/MM/dd").format(new Date());
		String name = UUID.randomUUID().toString().replaceAll("-", "");
		String cosPath = "/"+projectName+"/"+uploadTime+"/"+name + "." + ext;
		return cosPath;
	}
}
